﻿namespace FlexiCommerce.Web.UI.DynamicData
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;

    public class FlexiColumnProvider : System.Web.DynamicData.ModelProviders.ColumnProvider
    {
        #region Fields

        private XmlNode node;

        #endregion Fields

        #region Constructors

        public FlexiColumnProvider(FlexiTableProvider table, XmlNode node)
            : base(table)
        {
            if (node == null)
                throw new ArgumentNullException("node");
            this.node = node;
            if (node.Name == "id")
            {
                this.IsPrimaryKey = true;
                this.IsGenerated = true;
            }
            this.IsCustomProperty = false;
            this.IsSortable = true;
            if (node.Attributes["not-null"] != null)
            {
                this.Nullable = bool.Parse(node.Attributes["not-null"].Value);
            }
            this.ColumnType = table.EntityType.GetProperty(node.Attributes["name"].Value).PropertyType;
            this.EntityTypeProperty = table.EntityType.GetProperty(node.Attributes["name"].Value);
            this.Name = EntityTypeProperty.Name;
        }

        #endregion Constructors
    }
}